
import React from 'react'
import ConnectLoginCompent, {LoginCompent} from './login/login-compont'

interface PageWarpperContextProps {
    loginCompentRef?: React.RefObject<LoginCompent>
}

export const PageWarpperContext = React.createContext<PageWarpperContextProps>({})

const PageWarpper = function() {
    return function (WrappedComponent) {

        let loginCompentRef = React.createRef<LoginCompent>()

        return React.forwardRef((props, ref) => {
            return (
                <PageWarpperContext.Provider value={{ loginCompentRef: loginCompentRef}}>
                    <WrappedComponent {...props} ref={ref} />
                    <ConnectLoginCompent ref={ loginCompentRef }/>
                </PageWarpperContext.Provider>
            )
        })
    }
}

export default PageWarpper